﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Licenta1.Statements
{
    class AppendLightStatement:Statement
    {
        double x, y, z, r, g, b, fade;

        Expression parameters;

        public AppendLightStatement(Context context, Expression expr)
            : base(context)
        {
            parameters = expr;
        }

        private void CheckParameters()
        {
            try
            {
                ParameterList p_list = (ParameterList)parameters;

                x = (double)p_list.FirstValue;
                p_list = (ParameterList)p_list.SecondValue;
                y = (double)p_list.FirstValue;
                p_list = (ParameterList)p_list.SecondValue;
                z = (double)p_list.FirstValue;
                p_list = (ParameterList)p_list.SecondValue;
                r = (double)p_list.FirstValue;
                p_list = (ParameterList)p_list.SecondValue;
                g = (double)p_list.FirstValue;
                p_list = (ParameterList)p_list.SecondValue;
                b = (double)p_list.FirstValue;
                fade = (double)p_list.SecondValue;

            }
            catch (FormatException)
            {
                Console.WriteLine("Error handling parameters to Light.");
            }
        }

        public override void Execute()
        {
            CheckParameters();

            context.mp.rt.AddLight(new Licenta1.RayTracer.Vector(x, y, z), new Licenta1.RayTracer.Colors(r, g, b), fade);
        }
    }
}
